﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.MEP.Electric.Common;

namespace HYRElectric.PowerSystem
{
	public partial class DlgPowerSys : System.Windows.Forms.Form
	{
		public DlgPowerSys()
		{
			this.InitializeComponent();
		}

		private void DlgPowerSys_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.xmlHelper.LoadXml(this.path, "Root");
			this.rdoUniformNumber.Checked = true;
			this.rdoRenumbered.Checked = true;
			this.rdoWithPanel.Checked = true;
			this.LoadDlgData();
		}

		private void DlgPowerSys_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.SaveDlgData();
		}

		private void SaveDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYPanelSystem"));
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYPanelSystem", "Params"));
			this.xmlHelper.SetAttribute("NumberPrefix", this.txtNumberPrefix.Text);
			this.xmlHelper.SetAttribute("Delimiter", this.txtDelimiter.Text);
			this.xmlHelper.SetAttribute("AllocationCriteria", DlgPowerSys.allocationCriteria.ToString());
			this.xmlHelper.SetAttribute("AllocationSpecifications", DlgPowerSys.allocationSpecifications.ToString());
			this.xmlHelper.SetAttribute("ChoicePowerPrefix", DlgPowerSys.choicePowerPrefix.ToString());
			this.xmlHelper.SetAttribute("PowerPrefix", this.txtPowerPrefix.Text);
			this.xmlHelper.SaveXml("");
		}

		private void LoadDlgData()
		{
			this.xmlHelper.SelectNode(Path.Combine("Root", "HYPanelSystem", "Params"));
			string attribute = this.xmlHelper.GetAttribute("NumberPrefix");
			if (!string.IsNullOrEmpty(attribute))
			{
				this.txtNumberPrefix.Text = attribute;
			}
			string attribute2 = this.xmlHelper.GetAttribute("Delimiter");
			if (!string.IsNullOrEmpty(attribute2))
			{
				this.txtDelimiter.Text = attribute2;
			}
			string attribute3 = this.xmlHelper.GetAttribute("AllocationCriteria");
			if (!string.IsNullOrEmpty(attribute3))
			{
				int num = Convert.ToInt32(attribute3);
				if (num == 0)
				{
					this.rdoUniformNumber.Checked = true;
				}
				else if (num == 1)
				{
					this.rdoNumberAgo.Checked = true;
				}
				else if (num == 2)
				{
					this.rdoNumberAfter.Checked = true;
				}
			}
			string attribute4 = this.xmlHelper.GetAttribute("AllocationSpecifications");
			if (!string.IsNullOrEmpty(attribute4))
			{
				int num2 = Convert.ToInt32(attribute4);
				if (num2 == 0)
				{
					this.rdoRenumbered.Checked = true;
				}
				else if (num2 == 1)
				{
					this.rdoKeepExistingNumber.Checked = true;
				}
			}
			string attribute5 = this.xmlHelper.GetAttribute("ChoicePowerPrefix");
			if (!string.IsNullOrEmpty(attribute5))
			{
				int num3 = Convert.ToInt32(attribute5);
				if (num3 == 0)
				{
					this.rdoWithPanel.Checked = true;
				}
				else if (num3 == 1)
				{
					this.rdoCustomLoopPrefix.Checked = true;
				}
			}
			string attribute6 = this.xmlHelper.GetAttribute("PowerPrefix");
			if (!string.IsNullOrEmpty("PowerPrefix"))
			{
				this.txtPowerPrefix.Text = attribute6;
			}
		}

		private void rdoWithPanel_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.choicePowerPrefix = 0;
			this.txtPowerPrefix.Enabled = false;
		}

		private void rdoCustomLoopPrefix_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.choicePowerPrefix = 1;
			this.txtPowerPrefix.Enabled = true;
		}

		private void rdoUniformNumber_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.allocationCriteria = 0;
		}

		private void rdoNumberAgo_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.allocationCriteria = 1;
		}

		private void rdoNumberAfter_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.allocationCriteria = 2;
		}

		private void rdoRenumbered_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.allocationSpecifications = 0;
		}

		private void rdoKeepExistingNumber_CheckedChanged(object sender, EventArgs e)
		{
			DlgPowerSys.allocationSpecifications = 1;
		}

		private YArchitech.MEP.Electric.Common.XmlHelper xmlHelper = new YArchitech.MEP.Electric.Common.XmlHelper();

		private string path = Path.Combine(Product.WorkingLocation, "PanelSystem.xml");

		private const string Root = "Root";

		private const string Node = "HYPanelSystem";

		private const string ChildNode = "Params";

		private const string NumberPrefix = "NumberPrefix";

		private const string Delimiter = "Delimiter";

		private const string AllocationCriteria = "AllocationCriteria";

		private const string AllocationSpecifications = "AllocationSpecifications";

		private const string ChoicePowerPrefix = "ChoicePowerPrefix";

		private const string PowerPrefix = "PowerPrefix";

		public static int allocationCriteria;

		public static int allocationSpecifications;

		public static int choicePowerPrefix;
	}
}
